package com.yuanian.springbootProject.service.imp;

import com.yuanian.springbootProject.dao.TRoleMapper;
import com.yuanian.springbootProject.dao.TUserMapper;
import com.yuanian.springbootProject.dao.TUserRoleMapper;
import com.yuanian.springbootProject.dto.UserRoleName;
import com.yuanian.springbootProject.entity.TUserRole;
import com.yuanian.springbootProject.service.IUserRoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserRoleService implements IUserRoleService {

    @Resource
    private TUserMapper tUserMapper;

    @Resource
    private TRoleMapper tRoleMapper;

    @Resource
    private TUserRoleMapper userRoleMapper;

    @Override
    public int deleteByPrimaryKey(String id) {
        return userRoleMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(TUserRole record) {
        return userRoleMapper.insert(record);
    }

    @Override
    public int insertSelective(TUserRole record) {
        return userRoleMapper.insertSelective(record);
    }

    @Override
    public TUserRole selectByPrimaryKey(String id) {
        return userRoleMapper.selectByPrimaryKey(id);
    }

    @Override
    public UserRoleName selectWithNameByPrimaryKey(String id) {
        UserRoleName userRoleName = new UserRoleName();
        TUserRole tUserRole = userRoleMapper.selectByPrimaryKey(id);
        userRoleName.setId(tUserRole.getId());
        userRoleName.setUserId(tUserRole.getId());
        userRoleName.setRoleId(tUserRole.getId());
        userRoleName.setCreateDate(tUserRole.getCreateDate());
        userRoleName.setUpdateDate(tUserRole.getUpdateDate());
        userRoleName.setUserName(tUserMapper.selectByPrimaryKey(tUserRole.getUserId()).getUserName());
        userRoleName.setRoleName(tRoleMapper.selectByPrimaryKey(tUserRole.getRoleId()).getRoleName());
        return userRoleName;
    }

    @Override
    public int updateByPrimaryKeySelective(TUserRole record) {
        return userRoleMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(TUserRole record) {
        return userRoleMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<TUserRole> selectAll() {
        return userRoleMapper.selectAll();
    }

    @Override
    public List<UserRoleName> selectAllWithNames() {
        return userRoleMapper.selectAllWithNames();
    }
}
